﻿using CoachingOrganizer.Logic.Logic.Tools.MoneyCalculation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoachingOrganizer.Logic.Models.Tools.MoneyCalculation
{
    public class PeriodReportModel
    {
        private readonly DateTime _commonStart;
        private readonly DateTime _commonFinish;
        private readonly TimeSpan _period;
        private readonly int _index;
        private readonly DateTime _startDate;
        private readonly DateTime _finishDate;

        public DateTime StartDate
        {
            get { return _startDate; }
        }

        public DateTime FinishDate
        {
            get { return _finishDate; }
        }

        internal DateTime CommonStart
        {
            get { return _commonStart; }
        }

        internal DateTime CommonFinish
        {
            get { return _commonFinish; }
        }

        internal TimeSpan Period
        {
            get { return _period; }
        }

        internal int Index
        {
            get { return _index; }
        }

        internal Func<IEnumerable<PeriodGroupReportLogicBase>> EnumerateIncomesGroupsDelegate;

        internal Func<IEnumerable<PeriodGroupReportLogicBase>> EnumerateSpentsGroupsDelegate;

        internal Func<decimal> GetTotalIncomesDelegate;

        internal Func<decimal> GetTotalSpentsDelegate;

        public PeriodReportModel(DateTime commonStart, DateTime commonFinish, TimeSpan period, int index, DateTime startDate, DateTime finishDate)
        {
            _commonStart = commonStart;
            _commonFinish = commonFinish;
            _period = period;
            _index = index;
            _startDate = startDate;
            _finishDate = finishDate;
        }

        public IEnumerable<PeriodGroupReportModelBase> EnumerateIncomesGroups()
        {
            return EnumerateIncomesGroupsDelegate().Select(l => l.BaseModel);
        }

        public IEnumerable<PeriodGroupReportModelBase> EnumerateSpentsGroups()
        {
            return EnumerateSpentsGroupsDelegate().Select(l => l.BaseModel);
        }

        public decimal? GetTotalIncomes()
        {
            return GetTotalIncomesDelegate();
        }

        public decimal? GetTotalSpents()
        {
            return GetTotalSpentsDelegate();
        }
    }
}
